<?php

class Adept_Template_Compiler_ComponentTree 
{
    
    protected $compiledClass = 'TplDefaultClass';
    
    
    public function createTreeBuilder() 
    {
        return new Adept_Template_Builder_ComponentTree();	
    }	
    
    public function createParser() 
    {
    	return new Adept_Template_Parser_Tpl();
    }	
    
    /**
     * @param Adept_Template_Writer_Php $writer
     */
    public function generateHeader($writer) 
    {
            $writer->beginClass($this->getCompiledClass());
            $writer->beginFunction('doBody', '$root, $context', 'public');
    }
    
    /**
     * @param Adept_Template_Writer_Php $writer
     */
    public function generateFooter($writer) 
    {
        $writer->endFunction();
    	$writer->endClass();
    }
    
    /**
     * @param Adept_Template_Node $tree
     */
    public function compile($tree) 
    {
        $writer = new Adept_Template_Writer_Php();
    	$tree->preParse($this);
    	$tree->prepare();
    	$this->generateHeader($writer);
        $tree->generate($writer);
    	$this->generateFooter($writer);

    	return $writer->getCode();
    }
    
    public function getCompiledClass() 
    {
        return $this->compiledClass;
    }
    
    public function setCompiledClass($compiledClass) 
    {
        $this->compiledClass = $compiledClass;
    }
    
}